package asteroids.model.programs.parsing.expressions;

import java.util.Map;

import asteroids.model.CollisionObject;
import asteroids.model.Ship;


public class Sqrt extends MathematicalExpression  {

	public Sqrt(E expression) {
		super(expression);
	}
	public boolean canHaveAsSqrtExpression(Map<String,E> map,CollisionObject collisionObject){
		return ((double)getExpression().getContent(map, collisionObject)>= 0);
	}
	@Override
	public Object getContent(Map<String,E> map, CollisionObject givenCollisionObject) {
		if(getExpression().getContent(map, givenCollisionObject) instanceof Double){
		if(canHaveAsSqrtExpression(map,givenCollisionObject))
			return Math.sqrt((double)getExpression().getContent(map, givenCollisionObject));
		}
		if(givenCollisionObject.isShip()){
			Ship ship = (Ship)givenCollisionObject;
			ship.getProgram().setMistake();
		}
		System.out.println("There was a mistake made in your initialisation, please try again.");
		return null;
	}
}
